<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/6/19
  Time: 18:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>合同列表</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.5.6/css/layui.css">
</head>
<body>
<table id="contractTable" lay-filter="contractTable"></table>
<script src="${pageContext.request.contextPath}/static/js/jquery-3.6.0.js"></script>
<script src="https://cdn.staticfile.org/layui/2.5.6/layui.js"></script>
<script>
    layui.use(['table'], function(){
        var table = layui.table;

        // 表格渲染
        table.render({
            elem: '#contractTable',
            url: 'contract/quertyContractOrderClient',
            page: true,
            limit:10,
            limits:[5,10,20],
            cols: [[
                {field: 'contractNumber', title: '合同编号', width: 200},
                {field: 'quotationNumber', title: '订单编号', width: 200},
                {field: 'clientName', title: '客户姓名', width: 100},
                {field: 'supplier', title: '供应商', width: 200},
                {field: 'contractTime', title: '签约时间', width: 100},
                {field: 'contractStatus', title: '合同状态', width: 100,templet:function(b){
                       if (b.contractStatus=="0"){
                            return "未审核";
                        }else if (b.contractStatus=="1"){
                            return "审核中";
                        }else if (b.contractStatus=="2"){
                            return "审核通过";
                        }
                    }},
                {field: 'contractPay', title: '合同支付', width: 100,templet:function(paytype){
                        if (paytype.contractPay=="1"){
                            return "未付款";
                        }else if (paytype.contractPay=="2"){
                            return "已付款";
                        }
                    }},
                {field: 'contractSrc', title: '备注', width: 150},
                {field: '', title: '操作', width: 145,toolbar:'#toolbarDemo'}
            ]]
        });
        table.on('tool(contractTable)', function (obj) {
            var datas = obj.data; // 当前行的数据
            if (obj.event === 'audit') {
                var contractNumber = datas.contractNumber; // 获取当前行的合同编号
                // 弹出一个简单的弹窗
                layer.open({
                    title: '提示',
                    content: '确认要提交审核合同编号为 ' + contractNumber + ' 的合同吗？',
                    btn: ['确定', '取消'],
                    yes: function(index, layero) {
                        $.ajax({
                            "url": "contract/updateContract",
                            "type": "post",
                            "data": {contractNumber:contractNumber},
                            "dataType": "json",
                            //"contentType": "application/json;charset=utf-8",
                            "success": function (result) {
                                layer.msg(result.message);
                            },
                            "error": function () {
                                alert("出错了")
                            }
                        });
                        layer.close(index); // 关闭弹窗
                        var table = layui.table;
                        table.reload("contractTable");
                    },
                    btn2: function(index, layero) {
                        // 用户点击了取消按钮
                        // 在这里可以执行相应的取消操作
                        // ...
                        layer.close(index); // 关闭弹窗

                    }
                });
            }
        });
    });

</script>
</body>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="audit">提交</button>
    </div>
</script>
</html>
